<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/views/global/taglibs.jsp"%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath %>">
<%@include file="/views/global/ShopInclude.jsp" %>
<link href="static/css/page/address.css" rel="stylesheet" type="text/css">
<title>YOUR SHIPPING ADDRESS</title>
</head>
<body class="submitBg">
<!-- 顶部导航条  -->
<%@include file="/views/global/header.jsp" %>
<!-- 顶部导航条结束  -->

<c:set var="pageName" value="address"></c:set>
<%@include file="/views/global/BuyerHeader.jsp" %>

<div class="form-container center font fontColorGray">  <!-- 表单填写部分 -->
    <form id="submitForm" class="submit-form" action="" method="post">
    	<div class="form-content">
    		<div class="form-heading row hrTableBorder">
    			<div class="col-xs-11 form-title">
    				YOUR SHIPPING ADDRESSES 收货地址
    			</div>
    		</div>
    		<div class="address-content">
    			<div class="row">
    				<div class="address-box">
	    				<button id="btnNewAddess" type="button" class="font btn btn-success btn-lg pull-right" style="font-size: 13px;margin-bottom: 14px;">
	    				   ADD NEW ADDRESS 新增地址
	    				</button>
	    			</div>
    			</div>
    			<c:forEach var="item" items="${entityList }">
    			<div class="address-box">
    				<div class="address-info">
    					<div class="address-title">
	    					${item.userName } (${item.mobilePhone })
	    				</div>
	    				<div class="address-detail">
	    					<div class="address-location">
		    					${item.countryName }, ${item.stateName }, ${item.cityName } ${item.district }
		    				</div>
		    				<div class="address-street">
		    					${item.street }
		    				</div>
		    				<div class="address-postalCode">
		    					${item.postalCode }
		    				</div>
	    				</div>
    				</div>
    				<div class="address-control">
    					<div class="row">
    						<div class="col-xs-9">
    							<input type="button" class="btn btn-edit" value="EDIT 编辑" onclick="editNode(this, '${item.id }')"/>
    							<input type="button" class="btn btn-remove" value="REMOVE 删除" onclick="deleteNode(this, '${item.id}')" style="background-color: #f0f0f0;color: #a0a0a0;border-color: #ccc;"/>    
    						</div>
    						<div class="col-xs-3" style="font-size: 15px;text-align: right;">
    							<input type="checkbox" class="checkbox" name="isDefault" onclick="defaultNode(this, '${item.id}')"
    								 <c:if test="${1 eq item.isDefault }"> checked</c:if>/> Default 默认
    						</div>
    					</div>
    				</div>
    			</div>
    			</c:forEach>
    		</div>
    	</div>
	</form>
  </div>


<!-- 页尾 -->
<%@include file="/views/global/AdminScripts.jsp" %>
<%@include file="/views/global/footer.jsp" %>
<!-- 页尾结束 -->
</body>
<script type="text/javascript">
$(document).ready(function(){
	$("#btnNewAddess").click(function(){
		editNode(this, 0);
	});
});

function editNode(target, addressId){
	art.dialog.open('buyer/address/edit?id=' + addressId, {
		close: function(){
			window.location.reload();
		}, lock: true, top: '15%', cancel: true
	}, false);
}

function deleteNode(target, addressId){
	$("#submitForm").goAjax({
		semantic: false,
		checkLogin: true,
		url: 'buyer/address/delete',
		data:{id: addressId},
		success: function(jsonData) {
			if(true == jsonData.success){
				window.location.reload();
			} else {
				$("#msg").alert({type:'alert-danger', text: jsonData.message});
			}
		}
	});
}

function defaultNode(target, addressId){
	var checked = ("checked" == $(target).attr("checked"));
	$("#submitForm").goAjax({
		semantic: false,
		checkLogin: true,
		url: 'buyer/address/setAsDefault',
		data:{id: addressId, result: checked},
		success: function(jsonData) {
			if(true == jsonData.success){
				window.location.reload();
			} else {
				$("#msg").alert({type:'alert-danger', text: jsonData.message});
			}
		}
	});
}
function changePicture(target){
	
}
</script>
</html>
